package cn.xs.surveypark.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.xs.surveypark.dao.BaseDao;
import cn.xs.surveypark.domain.User;
import cn.xs.surveypark.service.UserService;
import cn.xs.surveypark.util.ValidateUtil;

@Service("userService")
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService{

	/**
	 * 重现该方法，覆盖注解
	 */
	@Resource(name="userDao")
	public void setDao(BaseDao<User> dao) {
		// TODO Auto-generated method stub
		super.setDao(dao);
	}

	/**
	 * 判断邮箱是否注册
	 */
	@Override
	public boolean isRegisted(String email) {
		// TODO Auto-generated method stub
		String hql = "from User u where u.email =? ";
		List<User> list = this.findgetEntityHQL(hql, email);
		return ValidateUtil.isValid(list);
	}

	@Override
	public User validateLoginInfo(String email, String password) {
		// TODO Auto-generated method stub
		String hql = "from User u where u.email = ? and u.password = ?";
		List<User> list = this.findgetEntityHQL(hql, email, password);
		return ValidateUtil.isValid(list)?list.get(0):null;
	}
	
}
